$(function() {
	$('.btn').on('tap', function() {
		var tel = $('#phone').val();
		if(!$('#phone').val()) {
			mui.toast('请输入您的电话号码');
			return false;
		};
		var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
		if(!myreg.test($('#phone').val())) {
			mui.toast('请输入正确的手机格式');
			return false;
		};
		var code = $('#password').val()
		if(!$('#password').val()) {
			mui.toast('请输入验证码');
			return false;
		};
		
		var mypwd = /^(?![0-9]+$)(?![a-zA-Z]+$)(?!([^(0-9a-zA-Z)]|[])+$)([^(0-9a-zA-Z)]|[]|[a-zA-Z]|[0-9]){6,}$/;
		var userPwd = $('#passwordNew').val()
		if(!mypwd.test($('#passwordNew').val())){
			mui.toast('请输入数字，符号，字母任意两种混合的密码');
			return false;
		}
		
		modifyPassword({
			code:code,
			userTel:tel,
			userPwd:userPwd
		},function(data){
			console.log(data)
			if(data.code==200){
				window.location.href = "l-userlogin.html"
			}else{
				mui.toast('修改失败！')
			}
		})
	})



	//获取验证码
	var validCode = true;
	$('.pswCode').on('tap', function() {
		if(!$('#phone').val()) {
			mui.toast('请输入您的电话号码');
			return false;
		};
		var tel = $('#phone').val();
		
		var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
		if(!myreg.test($('#phone').val())) {
			mui.toast('请输入正确的手机格式');
			return false;
		};
		
		var newNum = 60;
		if(validCode==true) {
			console.log(tel)
			validCode = false;
			var timer = setInterval(function() {
				newNum--;
				$('.pswCode').html(newNum);
				if(newNum == 0) {
					clearInterval(timer);
					$('.pswCode').html('获取验证码');
					validCode = true;

				}
			}, 1000);
			
			newuserCode({
				phoneNo:tel
			},function(data){
			console.log(data.data,888);
			});
			
		}
		

		
		
	});
});

//验证码
var newuserCode = function(params,callback){
	$.ajax({
		type: "get",
		url: window.address + "/user/getVerificationCode",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		data: params,
		dataType: 'json',
		success: function(data) {
			console.log(data)
			callback && callback(data);
		}
	});
}

//修改密码
var modifyPassword = function(params,callback){
	$.ajax({
		type: "post",
		url: window.address + "/user/forgetPassword",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		data: params,
		dataType: 'json',
		success: function(data) {
			console.log(data)
			callback && callback(data);
		}
	});
}
